package com.st.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.st.po.StudentNameListPo;
import com.st.vo.StudentNameListVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import com.st.dao.StudentMapper;
import com.st.pojo.Student;
import com.st.service.StudentService;
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService{

    @Resource
    private StudentMapper studentMapper;

    @Override
    public int batchInsert(List<Student> list) {
        return baseMapper.batchInsert(list);
    }

    @Override
    public List<StudentNameListVo> getList(StudentNameListPo studentNameListPo) {
        QueryWrapper<Student> qw = new QueryWrapper<>();
        qw.like(Student.COL_NAME,studentNameListPo.getName());
        qw.between(Student.COL_AGE,1,studentNameListPo.getAge());
        List<StudentNameListVo> listVos = new ArrayList<>();
        List<Student> students = studentMapper.selectList(qw);
        for (Student student1 : students) {
            StudentNameListVo studentNameListVo = new StudentNameListVo(student1.getName(),student1.getAge(),student1.getPhone());
            listVos.add(studentNameListVo);
        }
        return listVos;
    }


    @Override
    public List<StudentNameListVo> getNameList() {
        QueryWrapper<Student> qw = new QueryWrapper<>();
        qw.likeRight(Student.COL_NAME,"张");
        qw.likeRight(Student.COL_PHONE,"158");
        List<StudentNameListVo> listVos = new ArrayList<>();
        List<Student> students = studentMapper.selectList(qw);
        for (Student student : students) {
            StudentNameListVo studentNameListVo = new StudentNameListVo(student.getName(),student.getAge(),student.getPhone());
            listVos.add(studentNameListVo);
        }

        return listVos;
    }

    @Override
    public List<StudentNameListVo> getStudentList(String name,Integer age) {
       List<Student> studentlist = studentMapper.getStudentList(name,age);
        List<StudentNameListVo> listVos = new ArrayList<>();
        for (Student student : studentlist) {
            StudentNameListVo studentNameListVo = new StudentNameListVo(student.getName(),student.getAge(),student.getPhone());
            listVos.add(studentNameListVo);
        }
        return listVos;
    }
}
